/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package org.vz.attach.standard.service.impl;

import java.io.File;
import java.util.Date;
import java.util.List;

import javax.xml.ws.soap.SOAPBinding;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.springframework.beans.factory.annotation.Autowired;
import org.vz.attach.standard.domain.entity.ActionStatus;
import org.vz.attach.standard.domain.entity.Department;
import org.vz.attach.standard.domain.entity.DepartmentException;
import org.vz.attach.standard.domain.entity.Doctor;
import org.vz.attach.standard.domain.entity.DoctorException;
import org.vz.attach.standard.domain.entity.Fileregister;
import org.vz.attach.standard.domain.entity.FileregisterExction;
import org.vz.attach.standard.domain.entity.Patient;
import org.vz.attach.standard.domain.entity.PatientException;
import org.vz.attach.standard.domain.entity.PatientIdQuery;
import org.vz.attach.standard.domain.entity.PatientQueryException;
import org.vz.attach.standard.domain.entity.QueryFile;
import org.vz.attach.standard.domain.entity.QueryFileExcrption;
import org.vz.attach.standard.service.HIPService;
import org.vz.attach.standard.util.DataUtil;
import org.vz.attach.standard.util.LogUtil;
import org.vz.attach.standard.util.StringUtil;

/**
 * Examples code for spring boot with CXF services. HelloPortImpl is the
 * implementation for Hello interface. This class was generated by Apache CXF
 * 3.1.0 2015-05-18T13:02:03.098-05:00 Generated source version: 3.1.0
 */

/*
 * @javax.jws.WebService(serviceName = "HelloService", portName = "HelloPort",
 * targetNamespace = "http://service.ws.sample/", endpointInterface =
 * "sample.ws.service.Hello")
 */
@javax.jws.WebService(portName = "SoapPort", serviceName = "SOAPService", targetNamespace = "urn:hl7-org:v3", endpointInterface = "org.vz.attach.standard.service.HIPService")
// @javax.xml.ws.BindingType(value =
// "http://www.w3.org/2003/05/soap/bindings/HTTP/")
@javax.xml.ws.BindingType(SOAPBinding.SOAP12HTTP_BINDING)
@org.apache.cxf.annotations.SchemaValidation
public class HIPServiceImpl implements HIPService {
	ActionStatus actionStatus=new ActionStatus();
/*	private static final Logger LOG = Logger.getLogger(HIPServiceImpl.class
			.getName());*/

	@SuppressWarnings("unused")
	public java.lang.String HIPMessageServer(String action, String message) {		
		// LOG.info("接收到访问\naction的值:\n" + "messgae的值:\n"+messgae);
		new LogUtil(getClass()).info("接收到访问\naction的值:\n"+action + "\nmessgae的值:\n"
		
				+ message);
		String str = null;
		try {
			
			switch (action) {
			case "PatientRegistryAddRequest":
				if (actionStatus.isPatientActionstatus()) {
					Patient pat = patientSuccess(message);
					str = "<?xml version=\"1.0\" encoding=\"utf-8\" ?><PRPA_IN201312UV02 xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ITSVersion=\"XML_1.0\" xsi:schemaLocation=\"urn:hl7-org:v3 ../multicacheschemas/PRPA_IN201312UV02.xsd\" xmlns=\"urn:hl7-org:v3\"><id root=\"2.16.156.10011.0\" extension=\"22a0f9e0-4454-11dc-a6be-3603d686680R\"/><!--消息 ID--><CreationTime value="
							+ pat.getCreationTime()
							+ "/><interactionId root=\"2.16.840.1.113883.1.6\" extension=\"PRPA_IN201312UV02\"/><processingCode code=\"P\"/><processingModeCode code=\"R\"/><acceptAckCode code=\"NE\"/><receiver typeCode=\"RCV\"><device classCode=\"DEV\" determinerCode=\"INSTANCE\"><id root=\"2.16.156.10011.0.1.2\" extension=\"2.16.156.10011.0.1.2\"/></device></receiver><sender typeCode=\"SND\"><device classCode=\"DEV\" determinerCode=\"INSTANCE\"><id root=\"2.16.156.10011.0.1.1\" extension=\"2.16.156.10011.0.1.1\"/></device></sender><!--typeCode 为处理结果，AA 表示成功 AE 表示失败--><acknowledgement typeCode=\"AA\"><targetMessage><!--请求的消息 ID--><id root=\"2.16.156.10011.0\" extension="
							+ pat.getRequestId()
							+ "/></targetMessage><acknowledgementDetail><!--处理结果说明--><text>注册成功</text></acknowledgementDetail></acknowledgement><controlActProcess classCode=\"CACT\" moodCode=\"EVN\"><subject typeCode=\"SUBJ\"><registrationEvent classCode=\"REG\" moodCode=\"EVN\"><statusCode code=\"active\"/><subject1 typeCode=\"SBJ\"><patient classCode=\"PAT\"><!--平台注册的患者 ID --><id root=\"2.16.156.10011.0.2.1\" extension="
							+ pat.getPatientId()
							+ "/><statusCode code=\"active\"/><patientPerson classCode=\"PSN\" determinerCode=\"INSTANCE\"><!--姓名--><name use=\"L\">"
							+ pat.getPatientname()
							+ "</name></patientPerson></patient></subject1><custodian typeCode=\"CST\"><assignedEntity classCode=\"ASSIGNED\"><id root=\"2.16.156.10011.0.3.2\" extension="
							+ pat.getRegistrantId()
							+ "/><assignedPerson classCode=\"PSN\" determinerCode=\"INSTANCE\"><name use=\"L\">"
							+ pat.getRegistrantName()
							+ "</name></assignedPerson></assignedEntity></custodian></registrationEvent></subject></controlActProcess></PRPA_IN201312UV02>";
					actionStatus.setPatientActionstatus(false);
				} else {
					PatientException patEx = patientFailed(message);
					str = "<?xml version=\"1.0\" encoding=\"utf-8\" ?><PRPA_IN201313UV02 xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ITSVersion=\"XML_1.0\" xmlns=\"urn:hl7-org:v3\" xsi:schemaLocation=\"urn:hl7-org:v3 ../multicacheschemas/PRPA_IN201313UV02.xsd\"><id root=\"2.16.156.10011.0\" extension=\"22a0f9e0-4454-11dc-a6be-3603d686680R\"/><CreationTime value="
							+ patEx.getCreationTime()
							+ "/><interactionId root=\"2.16.840.1.113883.1.6\" extension=\"PRPA_IN201313UV02\"/><processingCode code=\"P\"/><processingModeCode code=\"R\"/><acceptAckCode code=\"NE\"/><receiver typeCode=\"RCV\"><device classCode=\"DEV\" determinerCode=\"INSTANCE\"><id root=\"2.16.156.10011.0.1.2\" extension=\"2.16.156.10011.0.1.2\"/></device></receiver><sender typeCode=\"SND\"><device classCode=\"DEV\" determinerCode=\"INSTANCE\"><id root=\"2.16.156.10011.0.1.1\" extension=\"2.16.156.10011.0.1.1\"/></device></sender><!--typeCode 为处理结果，AA 表示成功 AE 表示失败--><acknowledgement typeCode=\"AE\"><targetMessage><!--请求的消息 ID--><id root=\"2.16.156.10011.0\" extension=\"22a0f9e0-4454-11dc-a6be-3603d6866807\"/></targetMessage><acknowledgementDetail><!--处理结果说明--><text>"
							+ "由于 XXX 原因，注册失败"
							+ "</text></acknowledgementDetail></acknowledgement><controlActProcess classCode=\"CACT\" moodCode=\"EVN\"><subject typeCode=\"SUBJ\"><registrationRequest classCode=\"REG\" moodCode=\"RQO\"><statusCode code=\"active\"/><subject1 typeCode=\"SBJ\"><patient classCode=\"PAT\"><!--本地系统的患者 ID --><id root=\"2.16.156.10011.0.2.2\" extension="
							+ patEx.getPatientId()
							+ "/><statusCode code=\"active\"/><effectiveTime value=\"20111212141414\"/><patientPerson><!--身份证号--><id root=\"2.16.156.10011.1.3\" extension="
							+ patEx.getIdentity() + "/><!--姓名--><name use=\"L\">" + patEx.getName()
							+ "</name><!--联系电话--><telecom value=" + patEx.getTelecom()
							+ " use=\"H\"/><!--性别--><administrativeGenderCode code=" + patEx.getGenderCode()
							+ " codeSystem=\"2.16.156.10011.2.3.3.4\" displayName=" + patEx.getGender()
							+ "/><!--出生时间--><birthTime value=" + patEx.getBirthday() + "/><!--联系地址--><addr use="
							+ patEx.getAddr() + "><!--非结构化地址（完整地址描述） --><streetAddressLine partType=\"SAL\">"
							+ patEx.getStreetAddressLine()
							+ "</streetAddressLine><!--地址-省（自治区、直辖市） --><state language=\"CH\">" + patEx.getProvice()
							+ "</state><!--地址-市（地区） --><city>" + patEx.getCity() + "</city><!--地址-县（区） --><county>"
							+ patEx.getCounty() + "</county><!-- 地址-乡（镇、街道办事处） --><streetNameBase>"
							+ patEx.getStreetNameBase() + "</streetNameBase><!-- 地址-村（街、路、弄等） --><streetName>"
							+ patEx.getStreetName() + "</streetName><!-- 地址-门牌号码 --><houseNumber>" + patEx.getHouseNumber()
							+ "</houseNumber><!-- 邮政编码--><postalCode>" + patEx.getPostalCode()
							+ "</postalCode></addr><!--婚姻状况--><maritalStatusCode code=" + patEx.getMaritalStatusCode()
							+ " codeSystem=\"2.16.156.10011.2.3.3.5\" dis=\"\"playName=" + patEx.getMaritalStatusValue()
							+ "/><!--民族--><ethnicGroupCode code=" + patEx.getEthnicGroupCode()
							+ " codeSystem=\"2.16.156.10011.2.3.3.3\" displ=\"\"ayName=" + patEx.getEthnicGroupValue()
							+ "/><!--职业类别代码--><asEmployee classCode=\"EMP\"><occupationCode code="
							+ patEx.getAsEmployeeCode() + " codeSystem=\"2.16.156.10011.2.3.3.7\" di=\"\"splayName="
							+ patEx.getAsEmployeeValue()
							+ "/><employerOrganization classCode=\"ORG\" determinerCode=\"INSTANCE\"><!--工作单位名称--><name>"
							+ patEx.getWorkUnit() + "</name><contactParty classCode=\"CON\"><!--工作联系电话--><telecom value="
							+ patEx.getWorkTelPhone()
							+ " use=\"WP\"/></contactParty></employerOrganization></asEmployee><asOtherIDs classCode=\"PAT\"><!--健康卡号--><id root=\"2.16.156.10011.1.19\" extension="
							+ patEx.getHealthyCard()
							+ "/><scopingOrganization classCode=\"ORG\" determinerCode=\"INSTANCE\"><id root=\"2.16.156.10011.1.5\" extension=\"XXXXX\"/></scopingOrganization></asOtherIDs><asOtherIDs classCode=\"PAT\"><!--城乡居民健康档案编号--><id root=\"2.16.156.10011.1.2\" extension="
							+ patEx.getHealthrecordId()
							+ "/><scopingOrganization classCode=\"ORG\" determinerCode=\"INSTANCE\"><!--建档医疗机构组织机构代码--><id root=\"2.16.156.10011.1.5\" extension="
							+ patEx.getMedicalorganizationId()
							+ "/></scopingOrganization></asOtherIDs><!--联系人--><personalRelationship><code/><!--联系人电话--><telecom use=\"H\" value="
							+ patEx.getPhone()
							+ "/><relationshipHolder1 classCode=\"PSN\" determinerCode=\"INSTANCE\"><!--联系人姓名--><name>"
							+ patEx.getRelationshipName()
							+ "</name></relationshipHolder1></personalRelationship></patientPerson>           <providerOrganization classCode=\"ORG\" determinerCode=\"INSTANCE\"><id root=\"2.16.156.10011.1.5\" extension="
							+ patEx.getOrganizationCode() + "/><name use=\"L\">" + patEx.getOrganizationName()
							+ "</name><contactParty classCode=\"CON\"/></providerOrganization><!--医疗保险信息--><coveredPartyOf typeCode=\"COV\"><coverageRecord classCode=\"COV\" moodCode=\"EVN\"><beneficiary typeCode=\"BEN\"><beneficiary classCode=\"MBR\"><code code=\"1\" codeSystem=\"2.16.156.10011.2.3.1.248\" cod=\"\"eSystemName="
							+ patEx.getCoveredPartyCode() + " displayName=" + patEx.getCoveredPartyValue()
							+ "/></beneficiary></beneficiary></coverageRecord></coveredPartyOf></patient></subject1><author typeCode=\"AUT\"><assignedpatEx classCode=\"ASSIGNED\"><id root=\"2.16.156.10011.0.3.2\" extension="
							+ patEx.getRegistrantId()
							+ "/><assignedPerson classCode=\"PSN\" determinerCode=\"INSTANCE\"><name use=\"L\">"
							+ patEx.getRegistrantName()
							+ "</name></assignedPerson></assignedEntity></author></registrationRequest></subject></controlActProcess></PRPA_IN201313UV02>";
					actionStatus.setPatientActionstatus(true);
				}
				break;
			case "PatientRegistryFindCandidatesQuery":
				if (actionStatus.isPatientQrActionstatus()) {
					PatientIdQuery piq = patientIdQuerySuccess(message);
					str = "<?xml version=\"1.0\" encoding=\"utf-8\" ?><PRPA_IN201306UV02 xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ITSVersion=\"XML_1.0\" xmlns=\"urn:hl7-org:v3\" xsi:schemaLocation=\"urn:hl7-org:v3 ../multicacheschemas/PRPA_IN201306UV02.xsd\"><id root=\"2.16.156.10011.0\" extension=\"8D73520B-D489-4B70-8F4B-7B5C2D7961B5\"/><CreationTime value="
							+ piq.getCreationTime()
							+ "/><interactionId root=\"2.16.840.1.113883.1.6\" extension=\"PRPA_IN201306UV02\"/><processingCode code=\"T\"/><processingModeCode code=\"I\"/><acceptAckCode code=\"AA\"/><receiver typeCode=\"RCV\"><device classCode=\"DEV\" determinerCode=\"INSTANCE\"><id root=\"2.16.156.10011.0.1.2\" extension=\"2.16.156.10011.0.1.2\"/></device></receiver><sender typeCode=\"SND\"><device classCode=\"DEV\" determinerCode=\"INSTANCE\"><id root=\"2.16.156.10011.0.1.1\" extension=\"2.16.156.10011.0.1.1\"/></device></sender><acknowledgement typeCode=\"AA\"><!--应答代码，AA 成功，AE 失败，其它异常--><targetMessage><id root=\"2.16.156.10011.0\" extension=\"22a0f9e0-4454-11dc-a6be-3603d6866807\"/></targetMessage></acknowledgement><controlActProcess classCode=\"CACT\" moodCode=\"EVN\"><code code=\"PRPA_TE201306UV02\" codeSystem=\"2.16.840.1.113883.1.6\"/><subject typeCode=\"SUBJ\"><registrationEvent classCode=\"REG\" moodCode=\"EVN\"><statusCode code=\"active\"/><subject1 typeCode=\"SBJ\"><patient classCode=\"PAT\"><!--平台注册的患者 ID --><id root=\"2.16.156.10011.0.2.1\" extension="
							+ piq.getPatientId() + "/><statusCode code=\"active\"/><effectiveTime value="
							+ piq.getEffectiveTime()
							+ "/><patientPerson><!--身份证号--><id root=\"2.16.156.10011.1.3\" extension=" + piq.getIdnumber()
							+ "/><!--姓名--><name use=\"L\">" + piq.getName() + "</name><!--联系电话--><telecom value="
							+ piq.getTelecom() + " use=\"H\"/><!--性别--><administrativeGenderCode code=" + piq.getSexCode()
							+ "codeSystem=\"2.16.156.10011.2.3.3.4\" displayName=" + piq.getSexValue()
							+ "/><!--出生时间--><birthTime value=" + piq.getBrithday()
							+ "/><!--联系地址--><addr use=\"PUB\"><!--非结构化地址（完整地址描述） --><streetAddressLine partType=\"SAL\">"
							+ piq.getStreetAddressLine()
							+ "</streetAddressLine><!--地址-省（自治区、直辖市） --><state language=\"CH\">" + piq.getProvice()
							+ "</state><!--地址-市（地区） --><city>" + piq.getCity() + "</city><!--地址-县（区） --><county>"
							+ piq.getCounty() + "</county><!-- 地址-乡（镇、街道办事处） --><streetNameBase>" + piq.getStreetNameBase()
							+ "</streetNameBase><!-- 地址-村（街、路、弄等） --><streetName>" + piq.getStreetName()
							+ "</streetName><!-- 地址-门牌号码 --><houseNumber>" + piq.getHouseNumber()
							+ "</houseNumber><!-- 邮政编码--><postalCode>" + piq.getPostalCode()
							+ "</postalCode></addr><!--婚姻状况--><maritalStatusCode code=" + piq.getMaritalStatusCode()
							+ " codeSystem=\"2.16.156.10011.2.3.3.5\"displayName=" + piq.getMaritalStatusValue()
							+ "/><!--民族--><ethnicGroupCode code=" + piq.getEthnicGroupCode()
							+ " codeSystem=\"2.16.156.10011.2.3.3.3\"displayName=" + piq.getEthnicGroupvalue()
							+ "/><!--职业类别代码--><asEmployee classCode=\"EMP\"><occupationCode code=" + piq.getAsEmployeeCode()
							+ " codeSystem=\"2.16.156.10011.2.3.3.7\"displayName=" + piq.getAsEmployeeValue()
							+ "/><employerOrganization classCode=\"ORG\" determinerCode=\"INSTANCE\"><!--工作单位名称--><name>"
							+ piq.getWorkUnit() + "</name><contactParty classCode=\"CON\"><!--工作联系电话--><telecom value="
							+ piq.getWorkTelPhone()
							+ " use=\"WP\"/></contactParty></employerOrganization></asEmployee><asOtherIDs classCode=\"PAT\"><!--健康卡号--><id root=\"2.16.156.10011.1.19\" extension="
							+ piq.getHealthyId()
							+ "/><scopingOrganization classCode=\"ORG\" determinerCode=\"INSTANCE\"><id root=\"2.16.156.10011.1.5\" extension=\"XXXXX\"/></scopingOrganization></asOtherIDs><asOtherIDs classCode=\"PAT\"><!--城乡居民健康档案编号--><id root=\"2.16.156.10011.1.2\" extension="
							+ piq.getHealthrecordId()
							+ "/><scopingOrganization classCode=\"ORG\" determinerCode=\"INSTANCE\"><!--建档医疗机构组织机构代码--><id root=\"2.16.156.10011.1.5\" extension="
							+ piq.getMedicalorganizationId()
							+ "/></scopingOrganization></asOtherIDs><!--联系人--><personalRelationship><code/><!--联系人电话--><telecom use=\"H\" value="
							+ piq.getPhone()
							+ "/><relationshipHolder1 classCode=\"PSN\" determinerCode=\"INSTANCE\"><!--联系人姓名--><name>"
							+ piq.getRelationshipName()
							+ "</name></relationshipHolder1></personalRelationship></patientPerson><providerOrganization classCode=\"ORG\" determinerCode=\"INSTANCE\"><id root=\"2.16.156.10011.1.5\" extension=\"XXXXX\"/><name use=\"L\">"
							+ piq.getOrganization()
							+ "</name><contactParty classCode=\"CON\"/></providerOrganization><subjectOf1 typeCode=\"SBJ\"><queryMatchObservation classCode=\"COND\" moodCode=\"EVN\"><code code=\"PDQ\"/><value xsi:type=\"INT\" value=\"100\"/></queryMatchObservation></subjectOf1><!--医疗保险信息--><coveredPartyOf typeCode=\"COV\"><coverageRecord classCode=\"COV\" moodCode=\"EVN\"><beneficiary typeCode=\"BEN\"><beneficiary classCode=\"MBR\"><code code=\"1\" codeSystem=\"2.16.156.10011.2.3.1.248\"codeSystemName="
							+ piq.getCodeSystemName() + " displayName=" + piq.getDisplayName()
							+ "/></beneficiary></beneficiary></coverageRecord></coveredPartyOf></patient></subject1><custodian typeCode=\"CST\"><assignedEntity classCode=\"ASSIGNED\"><id root=\"2.16.156.10011.0.3.2\" extension="
							+ piq.getRegistrantId()
							+ "/><assignedPerson classCode=\"PSN\" determinerCode=\"INSTANCE\">              <name use=\"L\">"
							+ piq.getRegistrantName()
							+ "</name></assignedPerson></assignedEntity></custodian></registrationEvent></subject><queryAck><queryId root=\"2.16.156.10011.0\" extension=\"22a0f9e0-4454-11dc-a6be-3603d6866807\"/><!--AE 系统错误、NF 未找到数据、OK 找到数据、QE 查询参数错误--><queryResponseCode code=\"OK\"/></queryAck></controlActProcess></PRPA_IN201306UV02>";
					actionStatus.setPatientQrActionstatus(false);
				} else {
					PatientQueryException pqe = patientIdQueryFailed(message);
					str = "<?xml version=\"1.0\" encoding=\"utf-8\" ?><PRPA_IN201306UV02 ITSVersion=\"XML_1.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"urn:hl7-org:v3\" xsi:schemaLocation=\"urn:hl7-org:v3 ../multicacheschemas/PRPA_IN201306UV02.xsd\"><id extension=\"040CD76A-D0E-400B-9FD3-60387BCDE0EB\" /><CreationTime value="
							+ pqe.getCreationTime()
							+ "/><interactionId root=\"2.16.840.1.113883.1.6\" extension=\"PRPA_IN201306UV02\"/><processingCode code=\"T\"/><processingModeCode code=\"I\"/><acceptAckCode code=\"AA\"/><receiver typeCode=\"RCV\"><device classCode=\"DEV\" determinerCode=\"INSTANCE\"><id root=\"1.2.840.114350.1.13.999.567\"/></device></receiver><sender typeCode=\"SND\"><device classCode=\"DEV\" determinerCode=\"INSTANCE\"><id root=\"1.2.840.114350.1.13.999.234\"/></device></sender><!--typeCode 为处理结果，AA 表示成功 AE 表示失败--><acknowledgement typeCode=\"AE\"><targetMessage><!--请求消息 ID--><id extension="
							+ pqe.getRequstId() + "/></targetMessage><acknowledgementDetail><!--处理结果说明--><text>"
							+ pqe.getTreatmentresult()
							+ "</text></acknowledgementDetail></acknowledgement><controlActProcess classCode=\"CACT\" moodCode=\"EVN\"><code code=\"PRPA_TE201306UV02\" codeSystem=\"2.16.840.1.113883.1.6\"/><queryAck><queryId extension=\"040CD76A-ED0E-400B-9FD3-60387BCD\" /><queryResponseCode/></queryAck></controlActProcess></PRPA_IN201306UV02>";
					actionStatus.setPatientQrActionstatus(true);
				}
				break;
			case "AddProviderRequest":
				if (actionStatus.isDoctorActionstatus()) {
					Doctor doctor = doctorSuccess(message);
					str = "<?xml version=\"1.0\" encoding=\"utf-8\" ?><PRPM_IN301011UV01 xmlns=\"urn:hl7-org:v3\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ITSVersion=\"XML_1.0\" si:schemaLocation=\"urn:hl7-org:v3 ../multicacheschemas/PRPM_IN301011UV01.xsd\"><id root=\"240CD76A-ED0E-400B-9FD3-60387BCDE0EB\" extension=\"3D73520B-D489-4B70-8F4B-7B5C2D7961B5\"/><CreationTime value="
							+ doctor.getCreationTime()
							+ "/><interactionId root=\"2.16.840.1.113883.1.6\" extension=\"PRPM_IN301011UV01\"/><processingCode code=\"P\"/><processingModeCode code=\"I\"/><acceptAckCode code=\"AL\"/><receiver typeCode=\"RCV\"><telecom></telecom><device classCode=\"DEV\" determinerCode=\"INSTANCE\"><id root=\"1.2.840.114350.1.13.999.234\"/></device></receiver><sender typeCode=\"SND\"><telecom></telecom><device classCode=\"DEV\" determinerCode=\"INSTANCE\"><id root=\"1.2.840.114350.1.13.999.567\"/></device></sender><acknowledgement typeCode=\"AA\"><targetMessage><id root=\"040CD76A-ED0E-400B-9FD3-60387BCDE0EB\"extension=\"8D73520B-D489-4B70-8F4B-7B5C2D7961B5\"/></targetMessage><acknowledgementDetail><text></text></acknowledgementDetail></acknowledgement><controlActProcess classCode=\"CACT\" moodCode=\"EVN\"><code code=\"PRPM_TE301011UV01\" codeSystem=\"2.16.840.1.113883.1.6\"/><subject typeCode=\"SUBJ\"><registrationRequest classCode=\"REG\" moodCode=\"RQO\"><statusCode code=\"active\"></statusCode><subject1 typeCode=\"SBJ\"><healthCareProvider classCode=\"PROV\">            <!--医务人员 ID--><id root=\"2.16.156.10011.1.4\"extension="
							+ doctor.getDoctorId() + "></id><!--专业技术职务代码--><code code="
							+ doctor.getProfessionCode()
							+ " displayName=\" 主 任 医 师 \"codeSystem=\"2.16.156.10011.2.3.3.10\" codeSystemName=\"专业技术职务代码（ GB/T 8561-1988）\"></code><healthCarePrincipalPerson classCode=\"PSN\"determinerCode=\"INSTANCE\"><!--身份证号--><id root=\"2.16.156.10011.1.3\"extension="
							+ doctor.getIdentity() + "/><!--姓名--><name use=\"L\">" + doctor.getName()
							+ "</name><!--性别--><administrativeGenderCode code=" + doctor.getGenderCode()
							+ "codeSystem=\"2.16.156.10011.2.3.3.4\" displayName=" + doctor.getGender()
							+ " codeSystemName=\"生理性别代码表（GB/T 2261.1）\"/><!--出生日期--><birthTime value="
							+ doctor.getBirthday() + "/><!--出生地--><birthplace classCode=\"BIRTHPL\"><addr>"
							+ doctor.getAddress()
							+ "</addr></birthplace></healthCarePrincipalPerson></healthCareProvider></subject1><!--申请者--><author typeCode=\"AUT\"><assignedEntity classCode=\"ASSIGNED\"><!--医务人员 ID--><id root=\"2.16.156.10011.1.4\" extension="
							+ doctor.getApplyDoctorId()
							+ "/><assignedPerson classCode=\"PSN\" determinerCode=\"INSTANCE\"><name>"
							+ doctor.getApplyDoctorName()
							+ "</name></assignedPerson><representedOrganization classCode=\"ORG\"determinerCode=\"INSTANCE\"><!--科室号标识--><id root=\"2.16.156.10011.1.26\" extension="
							+ doctor.getApplyDeptId() + "/><name>" + doctor.getApplyDeptName()
							+ "</name><contactParty classCode=\"CON\"><contactPerson classCode=\"PSN\" determinerCode=\"INSTANCE\"><name>"
							+ doctor.getApplyContactPerson()
							+ "</name></contactPerson></contactParty></representedOrganization></assignedEntity></author></registrationRequest></subject></controlActProcess></PRPM_IN301011UV01>";
					actionStatus.setDoctorActionstatus(false);
				} else {
					DoctorException de =doctorFailed(message);
					str = "<?xml version=\"1.0\" encoding=\"utf-8\" ?><PRPM_IN301011UV01 xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ITSVersion=\"XML_1.0\" xmlns=\"urn:hl7-org:v3\" xsi:schemaLocation=\"urn:hl7-org:v3 ../multicacheschemas/PRPM_IN301011UV01.xsd\"><id extension=\"8D73520B-D489-4B70-8F4B-7B5C2D7961B5\"/><CreationTime value="
							+ de.getCreationTime()
							+ "/><interactionId root=\"2.16.840.1.113883.1.6\" extension=\"PRPM_IN301011UV01\"/><processingCode code=\"P\"/><processingModeCode code=\"I\"/><acceptAckCode code=\"AL\"/><receiver typeCode=\"RCV\"><telecom></telecom><device classCode=\"DEV\" determinerCode=\"INSTANCE\"><id root=\"1.2.840.114350.1.13.999.567\"/></device></receiver><sender typeCode=\"SND\"><telecom></telecom><device classCode=\"DEV\" determinerCode=\"INSTANCE\"><id root=\"1.2.840.114350.1.13.999.234\"/></device></sender><!--typeCode 为处理结果，AA 表示成功 AE 表示失败--><acknowledgement typeCode=\"AE\"><targetMessage><!--请求消息 ID--><id extension="
							+ de.getRequestId()
							+ "/></targetMessage><acknowledgementDetail><!--处理结果说明--><text>" + "由于 XXX 原因，注册失败"
							+ "</text></acknowledgementDetail></acknowledgement><controlActProcess classCode=\"ACTN\" moodCode=\"APT\"><subject typeCode=\"SUBJ\"><registrationRequest classCode=\"REG\" moodCode=\"RQO\"><statusCode></statusCode><subject1 typeCode=\"SBJ\"><assignedEntity classCode=\"ASSIGNED\"></assignedEntity></subject1><author typeCode=\"AUT\"><assignedEntity classCode=\"ASSIGNED\"><id></id></assignedEntity></author></registrationRequest></subject></controlActProcess></PRPM_IN301011UV01>";
					actionStatus.setDoctorActionstatus(true);
				}
				break;
			case "AddOrganizationRequest":
				if (actionStatus.isDeptActionstatus()) {
					Department departMent = departmentSuccess(message);
					str = "<?xml version=\"1.0\" encoding=\"utf-8\" ?><PRPM_IN401031UV01 xmlns=\"urn:hl7-org:v3\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ITSVersion=\"XML_1.0\" si:schemaLocation=\"urn:hl7-org:v3 ../multicacheschemas/PRPM_IN401031UV01.xsd\"><id root=\"140CD76A-ED0E-400B-9FD3-60387BCDE0EB\" extension=\"8D73520B-D489-4B70-8F4B-7B5C2D7961B5\"/><CreationTime value="
							+ departMent.getCreationTime()
							+ "/><interactionId root=\"2.16.840.1.113883.1.6\" extension=\"PRPM_IN401031UV01\"/><processingCode code=\"P\"/><processingModeCode code=\"I\"/><acceptAckCode code=\"AL\"/><receiver typeCode=\"RCV\"><device classCode=\"DEV\" determinerCode=\"INSTANCE\"><id root=\"1.2.840.114350.1.13.999.234\"/></device></receiver><sender typeCode=\"SND\"><device classCode=\"DEV\" determinerCode=\"INSTANCE\"><id root=\"1.2.840.114350.1.13.999.567\"/></device></sender><acknowledgement typeCode=\"AA\"><targetMessage><id root=\"040CD76A-ED0E-400B-9FD3-60387BCDE0EB\" extension=\"8D73520B-D489-4B70-8F4B-7B5C2D7961B5\"/></targetMessage><acknowledgementDetail><text/></acknowledgementDetail></acknowledgement><controlActProcess classCode=\"CACT\" moodCode=\"EVN\"><code code=\"PRPM_TE401011UV01\" codeSystem=\"2.16.840.1.113883.1.6\"/><subject typeCode=\"SUBJ\"><registrationRequest classCode=\"REG\" moodCode=\"RQO\"><statusCode code=\"active\"/><subject1 typeCode=\"SBJ\"><assignedEntity classCode=\"ASSIGNED \"><!--医疗卫生机构（科室）标识-科室为例--><id root=\"2.16.156.10011.1.26\" extension="
							+ departMent.getDbtIdentification() + "/><!--医疗卫生机构（科室）类别-科室为例--><code code="
							+ departMent.getDepartmentTypeCode() + " displayName="
							+ departMent.getDepartmentTypeValue() + " codeSystem="
							+ departMent.getDepartmentTypeCodeSystem() + " codeSystemName="
							+ departMent.getDepartmentTypeSystemName()
							+ "/><!--医疗卫生机构（科室）角色名称--><name/><assignedPrincipalOrganization classCode=\"ORG\" determinerCode=\"INSTANCE\"><!--医疗卫生机构（科室）实体名称--><name>"
							+ departMent.getDbtName()
							+ "</name></assignedPrincipalOrganization></assignedEntity></subject1><author typeCode=\"AUT\"><assignedEntity classCode=\"ASSIGNED\"><!--医务人员 ID--><id root=\"2.16.156.10011.1.4\" extension="
							+ departMent.getHealthcareId()
							+ "/><assignedPerson classCode=\"PSN\" determinerCode=\"INSTANCE\"><name>"
							+ departMent.getAssignedPreson()
							+ "</name></assignedPerson><representedOrganization classCode=\"ORG\" determinerCode=\"INSTANCE\"><!--科室号标识--><id root=\"2.16.156.10011.1.26\" extension="
							+ departMent.getDbtIdentifications() + "/><name>" + departMent.getDepartmentName()
							+ "</name><contactParty classCode=\"CON\"><contactPerson classCode=\"PSN\" determinerCode=\"INSTANCE\"><name>"
							+ departMent.getContactPartyName()
							+ "</name></contactPerson></contactParty></representedOrganization></assignedEntity></author></registrationRequest></subject></controlActProcess></PRPM_IN401031UV01>";
					actionStatus.setDeptActionstatus(false);
				} else {
					DepartmentException departEx = departmentFailed(message);
					str = "<?xml version=\"1.0\" encoding=\"utf-8\" ?><PRPM_IN401031UV01 xmlns=\"urn:hl7-org:v3\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ITSVersion=\"XML_1.0\" xsi:schemaLocation=\"urn:hl7-org:v3 ../multicacheschemas.xsd\"><id extension=\"8D73520B-D489-4B70-8F4B-7B5C2D7961B5\"/><CreationTime value="
							+ departEx.getCreationTime()
							+ "/><interactionId root=\"2.16.840.1.113883.1.6\" extension=\"PRPM_IN401031UV01\"/><processingCode code=\"P\"/><processingModeCode code=\"I\"/><acceptAckCode code=\"AL\"/><receiver typeCode=\"RCV\"><device classCode=\"DEV\" determinerCode=\"INSTANCE\"><id root=\"1.2.840.114350.1.13.999.567\"/></device></receiver><sender typeCode=\"SND\"><device classCode=\"DEV\" determinerCode=\"INSTANCE\"><id root=\"1.2.840.114350.1.13.999.234\"/></device></sender><!--typeCode 为处理结果，AA 表示成功 AE 表示失败--><acknowledgement typeCode=\"AE\"><targetMessage><!--请求的消息 ID--><id extension="
							+ departEx.getRequestId()
							+ "/></targetMessage><acknowledgementDetail><!--处理结果说明--><text>" + departEx.getTreatmentresult()
							+ "</text></acknowledgementDetail></acknowledgement><controlActProcess classCode=\"CACT\" moodCode=\"EVN\"><code code=\"PRPM_TE401011UV01\" codeSystem=\"2.16.840.1.113883.1.6\"/><subject typeCode=\"SUBJ\"><registrationRequest classCode=\"REG\" moodCode=\"RQO\"><statusCode></statusCode><subject1 typeCode=\"SBJ\"><assignedEntity classCode=\"ASSIGNED\"></assignedEntity></subject1><author typeCode=\"AUT\"><assignedEntity classCode=\"ASSIGNED\"><id></id></assignedEntity></author></registrationRequest></subject></controlActProcess></PRPM_IN401031UV01>";
					actionStatus.setDeptActionstatus(true);
				}
				break;
			case "ProvideAndRegisterDocumentSet":
				if (actionStatus.isFileRgtActionstatus()) {
					Fileregister fileReg = fileRegSuccess(message);
					str = "<RegistryResponse xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"urn:hl7-org:v3\" xsi:schemaLocation=\"urn:hl7-org:v3 ../multicacheschemas/RegistryResponse.xsd\"><Id root=\"响应消息 OID\" extension="
							+ fileReg.getResponseId() + "/><TargetId root=\"请求消息 OID\" extension="
							+ fileReg.getRequestId() + "/><Response id=\"Document.1\" documentUniqueId="
							+ fileReg.getRepositoryId()
							+ " repositoryId=\"1AD6DD12-569E-420B-9EEF-32E903536F89\" status="
							+ fileReg.getStatus()
							+ " doumentUrl=\"http://192.168.1.145:57773/HUB.02.2^HUB.05.1^20121116112942^会诊记录.xml\"><!--Document.1..n 多文档提交的顺序号单文档默认 1，documentUniqueId 唯一文档号，repositoryId 响应编号，doumentUrl 在区域交换认证后可调路径，status 以 AA 为正常，其它异常--><Detail>success</Detail></Response></RegistryResponse>";
					actionStatus.setFileRgtActionstatus(false);
				} else {
					FileregisterExction fileEx = fileRegFailed(message);
					str = "<RegistryResponse xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"urn:hl7-org:v3\" xsi:schemaLocation=\"urn:hl7-org:v3 ../multicacheschemas/RegistryResponse.xsd\"><Id root=\"响应消息 OID\" extension="
							+ fileEx.getResponseId() + "/><TargetId root=\"请求消息 OID\" extension="
							+ fileEx.getRequestId() + "/><Response id=\"Document.1\" status="
							+ fileEx.getStatus() + " ><Detail>" + fileEx.getText() + "</Detail></Response>";
					actionStatus.setFileRgtActionstatus(true);
				}
				break;
			case "GetDocumentSetRetrieveInfo":
				if (actionStatus.isFileQrActionstatus()) {
					QueryFile qf = queryFileSuccess(message);
					str = "<GetDocumentStroedInfoResponse xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"urn:hl7-org:v3\" xsi:schemaLocation=\"urn:hl7-org:v3 ../multicacheschemas/GetDocumentStroedInfoResponse.xsd\" status=\"AA\"><Id root=\"响应消息 OID\" extension="
							+ qf.getResponseId() + "/><TargetId root=\"请求消息 OID\" extension="
							+ qf.getRequestId()
							+ "/><DocumentSet><DocumentUniqueId>D55D2100-090D-4B33-9CFB-7BBC542B02A1</DocumentUniqueId><RepositoryUniqueId>1AD6DD12-569E-420B-9EEF-32E903536F89</RepositoryUniqueId><DocumentTitle>"
							+ qf.getDocumentTitle() + "</DocumentTitle><CreateTime>" + qf.getCreateTime()
							+ "</CreateTime><AuthorName>" + qf.getAuthorName() + "</AuthorName><PatientID>"
							+ qf.getPatientID() + "</PatientID><PatientName>" + qf.getPatientName()
							+ "</PatientName><ServerOrganization>" + qf.getServerOrganization()
							+ "</ServerOrganization><EpisodeID>" + qf.getEpisodeID() + "</EpisodeID><InTime>" + qf.getInTime()
							+ "</InTime><OutTime>" + qf.getOutTime() + "</OutTime><AdmissionDepart>" + qf.getAdmissionDepart()
							+ "</AdmissionDepart><AdmissionDoctor>" + qf.getAdmissionDoctor()
							+ "</AdmissionDoctor><AdmissionType>" + qf.getAdmissionType()
							+ "</AdmissionType><DiagnosisResult>" + qf.getDiagnosisResult()
							+ "</DiagnosisResult><DocUrl>http://192.168.1.145:57773/HUB.02.2^HUB.05.1^20121116112942^会诊记录.xml</DocUrl></DocumentSet><Detail>"
							+ qf.getDetail() + "</Detail></GetDocumentStroedInfoResponse>";
					actionStatus.setFileQrActionstatus(false);
				} else {
					QueryFileExcrption qfe = queryFileFailed(message);
					str = "<GetDocumentStroedInfoResponse xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"urn:hl7-org:v3\" xsi:schemaLocation=\"urn:hl7-org:v3 ../multicacheschemas/GetDocumentStroedInfoResponse.xsd\" status=\"AE\"><Id root=\"响应消息 OID\" extension="
							+ qfe.getResponseId() + "/><TargetId root=\"请求消息 OID\" extension="
							+ qfe.getRequestId() + "/>117<Detail>" + qfe.getDetail()
							+ "</Detail></GetDocumentStroedInfoResponse>";
					actionStatus.setFileQrActionstatus(true);
				}
				break;
			}
			

		} catch (java.lang.Exception ex) {
			ex.printStackTrace();
			throw new RuntimeException(ex);
		}
		return str;
	}
	
	
	/**
	 * 
	 * @description  患者信息注册服务-响应消息（成功）
	 * @author       lanxuyu
	 * @CreateTime   2017年10月21日 上午11:09:09
	 * @param message
	 * @return
	 */
	public Patient patientSuccess(String message){
		Patient patient = new Patient();
		try {			
	        Document document = DocumentHelper.parseText(message);	        
            Element registrantIdNode = (Element) document.selectSingleNode("/*[name()='PRPA_IN201311UV02']/*[name()='controlActProcess']/*[name()='subject']/*[name()='registrationRequest']/*[name()='subject1']/*[name()='patient']/*[name()='id']");
            Element userNode = (Element) document.selectSingleNode("/*[name()='PRPA_IN201311UV02']/*[name()='controlActProcess']/*[name()='subject']/*[name()='registrationRequest']/*[name()='subject1']/*[name()='patient']/*[name()='patientPerson']");
            patient.setPatientId(userNode.element("id").attributeValue("extension"));
            patient.setRegistrantName(registrantIdNode.getText());
            patient.setPatientname(userNode.element("name").getText());
            
	        patient.setRegistrantId(registrantIdNode.attributeValue("extension"));
	        patient.setCreationTime(StringUtil.dateToString(new Date(),"yyyy-MM-dd"));
	        patient.setRequestId(StringUtil.uuid());
	        
	        System.out.println(patient.toString());
	        
		} catch (DocumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return patient;
	}
	/**
	 * 
	 * @description  患者信息注册服务-响应消息（异常）
	 * @author       lanxuyu
	 * @CreateTime   2017年10月21日 上午11:08:55
	 * @param message
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public PatientException patientFailed(String message){
		PatientException patientException = new PatientException();
		try {			
			Document document = DocumentHelper.parseText(message);	        
            Element userNode = (Element) document.selectSingleNode("/*[name()='PRPA_IN201311UV02']/*[name()='controlActProcess']/*[name()='subject']/*[name()='registrationRequest']/*[name()='subject1']/*[name()='patient']/*[name()='patientPerson']");
            Element CoveredPartyNode=(Element)document.selectSingleNode("/*[name()='PRPA_IN201311UV02']/*[name()='controlActProcess']/*[name()='subject']/*[name()='registrationRequest']/*[name()='subject1']/*[name()='patient']/*[name()='coveredPartyOf']/*[name()='coverageRecord']/*[name()='beneficiary']/*[name()='beneficiary']/*[name()='code']");
            Element patientNode=(Element)document.selectSingleNode("/*[name()='PRPA_IN201311UV02']/*[name()='controlActProcess']/*[name()='subject']/*[name()='registrationRequest']/*[name()='subject1']/*[name()='patient']");
            Element assignedEntityNode=(Element)document.selectSingleNode("/*[name()='PRPA_IN201311UV02']/*[name()='controlActProcess']/*[name()='subject']/*[name()='registrationRequest']/*[name()='author']/*[name()='assignedEntity']");
            Element addrNode=(Element)userNode.element("addr");
            Element asEmployeeNode=(Element)userNode.element("asEmployee");
            Element employerOrganizationNode=asEmployeeNode.element("employerOrganization");
            List<Element> asOtherIDsNodes=userNode.elements("asOtherIDs");
            Element personalRelationshipNode=(Element)userNode.element("personalRelationship");
            Element providerOrganizationNode=(Element)patientNode.element("providerOrganization");
           
            patientException.setPatientId(userNode.element("id").attributeValue("extension"));
            patientException.setName(userNode.element("name").getText());
            patientException.setCreationTime(StringUtil.dateToString(new Date(),"yyyy-MM-dd"));
            patientException.setTelecom(userNode.element("telecom").attributeValue("value"));
            patientException.setGender(userNode.element("administrativeGenderCode").attributeValue("displayName"));;
            patientException.setGenderCode(userNode.element("administrativeGenderCode").attributeValue("code"));
            patientException.setBirthday(userNode.element("birthTime").attributeValue("value"));
            patientException.setAddr(addrNode.element("streetAddressLine").getText());
            patientException.setStreetAddressLine(addrNode.element("streetAddressLine").getText());
            patientException.setProvice(addrNode.element("state").getText());
            patientException.setCity(addrNode.element("city").getText());
            patientException.setCounty(addrNode.element("county").getText());
            patientException.setStreetNameBase(addrNode.element("streetNameBase").getText());
            patientException.setStreetName(addrNode.element("streetName").getText());
            patientException.setHouseNumber(addrNode.element("houseNumber").getText());
            patientException.setPostalCode(addrNode.element("postalCode").getText());
            patientException.setMaritalStatusCode( userNode.element("maritalStatusCode").attributeValue("code"));
            patientException.setMaritalStatusValue(userNode.element("maritalStatusCode").attributeValue("displayName"));
            patientException.setEthnicGroupCode(userNode.element("ethnicGroupCode").attributeValue("code"));
            patientException.setEthnicGroupValue(userNode.element("ethnicGroupCode").attributeValue("displayName"));
            patientException.setAsEmployeeCode(asEmployeeNode.element("occupationCode").attributeValue("code"));
            patientException.setAsEmployeeValue(asEmployeeNode.element("occupationCode").attributeValue("displayName"));
            patientException.setWorkUnit(employerOrganizationNode.element("name").getText());
            patientException.setWorkTelPhone(employerOrganizationNode.element("contactParty").element("telecom").attributeValue("value"));
            patientException.setHealthyCard(asOtherIDsNodes.get(0).element("id").attributeValue("extension"));
            patientException.setHealthrecordId(asOtherIDsNodes.get(1).element("id").attributeValue("extension"));
            patientException.setMedicalorganizationId(asOtherIDsNodes.get(1).element("scopingOrganization").element("id").attributeValue("extension"));
            patientException.setPhone(personalRelationshipNode.element("telecom").attributeValue("value"));
            
            patientException.setRelationshipName(personalRelationshipNode.element("relationshipHolder1").element("name").getText());
            patientException.setOrganizationCode(providerOrganizationNode.element("id").attributeValue("extension"));
            patientException.setOrganizationName(providerOrganizationNode.element("name").getText());
            patientException.setCoveredPartyCode(CoveredPartyNode.attributeValue("code"));
            patientException.setCoveredPartyValue(CoveredPartyNode.attributeValue("displayName"));
            patientException.setRegistrantId(assignedEntityNode.element("id").attributeValue("extension"));
            patientException.setRegistrantName(assignedEntityNode.element("assignedPerson").element("name").getText());
            System.out.println(patientException.toString());

		} catch (DocumentException e) {
			e.printStackTrace();
		}
		return patientException;
	}
	
	/**
	 * 
	 * @description  获取病人基本信息 PatientRegistryFindCandidtesQuery(成功)
	 * @author       lanxuyu
	 * @CreateTime   2017年10月21日 上午11:08:34
	 * @param message
	 * @return
	 */
	public PatientIdQuery patientIdQuerySuccess(String message){
		PatientIdQuery patientIdQuery = new PatientIdQuery();
		try {
			Document document = DocumentHelper.parseText(message);
			Element livingSubjectIdNode=(Element)document.selectSingleNode("/*[name()='PRPA_IN201305UV02']/*[name()='controlActProcess']/*[name()='queryByParameter']/*[name()='parameterList']/*[name()='livingSubjectId']");
			patientIdQuery.setPatientId(livingSubjectIdNode.element("value").attributeValue("extension"));
			patientIdQuery.setCreationTime(StringUtil.dateToString(new Date(),"yyyy-MM-dd"));
			patientIdQuery.setEffectiveTime("20111212141414");
			patientIdQuery.setIdnumber("120109197706015516");
			patientIdQuery.setName("刘永好");
			patientIdQuery.setTelecom("028-2222444");
			patientIdQuery.setSexCode("1");
			patientIdQuery.setSexValue("男性");
			patientIdQuery.setBrithday("19570323");
			patientIdQuery.setAddr("PUB");
			patientIdQuery.setStreetAddressLine("四川省成都市双流县红沙村 3 号");
			patientIdQuery.setProvice("广东省");
			patientIdQuery.setCity("广州市");
			patientIdQuery.setCounty("越秀区");
			patientIdQuery.setStreetNameBase("童心街");
			patientIdQuery.setStreetName("下塘西路");
			patientIdQuery.setHouseNumber("39 号");
			patientIdQuery.setPostalCode("510000");
			patientIdQuery.setMaritalStatusCode("10");
			patientIdQuery.setMaritalStatusValue("未婚");
			patientIdQuery.setEthnicGroupCode("01");
			patientIdQuery.setEthnicGroupvalue("汉族");
			patientIdQuery.setAsEmployeeCode("13");
			patientIdQuery.setAsEmployeeValue("专业技术人员");
			patientIdQuery.setWorkUnit("XXX 学校");
			patientIdQuery.setWorkTelPhone("028-9999999");
			patientIdQuery.setHealthyId("38273N237");
			patientIdQuery.setHealthrecordId("38273N237");
			patientIdQuery.setMedicalorganizationId("XXXXX");
			patientIdQuery.setPhone("028-8888888");
			patientIdQuery.setRelationshipName("刘好");
			patientIdQuery.setOrganization("无锡中医院");
			patientIdQuery.setCodeSystemName("医疗保险类别代码");
			patientIdQuery.setDisplayName("城镇职工基本医疗保险");
			patientIdQuery.setRegistrantId("登记人 ID");
			patientIdQuery.setRegistrantName("赵武");
		} catch (DocumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return patientIdQuery;
	}
	
	/**
	 * 
	 * @description  获取病人基本信息 PatientRegistryFindCandidtesQuery(异常)
	 * @author       lanxuyu
	 * @CreateTime   2017年10月21日 上午11:07:59
	 * @param message
	 * @return
	 */
	public PatientQueryException patientIdQueryFailed(String message){
		PatientQueryException patientQueryException = new PatientQueryException();
		patientQueryException.setCreationTime(StringUtil.dateToString(new Date(),"yyyy-MM-dd"));
		patientQueryException.setRequstId("22a0f9e0-4454-11dc-a6be-3603d6866807");
		patientQueryException.setTreatmentresult("由于 XXX 原因，查询失败");
		return patientQueryException;
	
	}
	
	
	/**
	 * 医护人员注册服务 AddProviderRequest(成功)
	 * */
	public Doctor doctorSuccess(String message){
		
		Doctor doctor=new Doctor();
        try {
        	Document document = DocumentHelper.parseText(message);
			Element departmentNode=(Element)document.selectSingleNode("/*[name()='PRPM_IN301010UV01']/*[name()='controlActProcess']/*[name()='subject']/*[name()='registrationRequest']/*[name()='subject1']/*[name()='healthCareProvider']");
			Element assignedEntityNode=(Element)document.selectSingleNode("/*[name()='PRPM_IN301010UV01']/*[name()='controlActProcess']/*[name()='subject']/*[name()='registrationRequest']/*[name()='author']/*[name()='assignedEntity']");
			
			Element healthCarePrincipalPersonNode=departmentNode.element("healthCarePrincipalPerson");
				doctor.setCreationTime(StringUtil.dateToString(new Date(),"yyyy-MM-dd"));
				doctor.setDoctorId(departmentNode.element("id").attributeValue("extension"));
				doctor.setProfessionCode(departmentNode.element("code").attributeValue("code"));
				doctor.setProfessionValue(departmentNode.element("code").attributeValue("displayName"));
				doctor.setIdentity(healthCarePrincipalPersonNode.element("id").attributeValue("extension"));
			    doctor.setName(healthCarePrincipalPersonNode.element("name").getText());
			    doctor.setGenderCode(healthCarePrincipalPersonNode.element("administrativeGenderCode").attributeValue("code"));
			    doctor.setGender(healthCarePrincipalPersonNode.element("administrativeGenderCode").attributeValue("displayName"));
			    doctor.setBirthday(healthCarePrincipalPersonNode.element("birthTime").attributeValue("value"));
			    doctor.setAddress(healthCarePrincipalPersonNode.element("birthplace").element("addr").getText());
	
			    doctor.setApplyDoctorId(assignedEntityNode.element("id").attributeValue("extension"));
			    doctor.setApplyDoctorName(assignedEntityNode.element("assignedPerson").element("name").getText());
			   
	
			    doctor.setApplyDeptId(assignedEntityNode.element("representedOrganization").element("id").attributeValue("extension"));
			    doctor.setApplyDeptName(assignedEntityNode.element("representedOrganization").element("name").getText());
			    doctor.setApplyContactPerson(assignedEntityNode.element("representedOrganization").element("contactParty").element("contactPerson").element("name").getText());
			    
			
		} catch (DocumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return doctor;
	}
	
	/**
	 * 医护人员注册服务 AddProviderRequest(失败)
	 * */
	public DoctorException doctorFailed(String message){
		DoctorException doctorException = new DoctorException();
		doctorException.setCreationTime(StringUtil.dateToString(new Date(),"yyyy-MM-dd"));
	    doctorException.setRequestId(StringUtil.uuid());
	    doctorException.setTreatmentresult(""); 
			
		return doctorException;
	}
	
	
	
	/**
	 * 创建科室 AddOrganizationRequest (成功)
	 * */
	public Department departmentSuccess(String message){
		Department department = new Department();
		try{
			Document document = DocumentHelper.parseText(message);
		Element departmentNode=(Element)document.selectSingleNode("/*[name()='PRPM_IN401030UV01']/*[name()='controlActProcess']/*[name()='subject']/*[name()='registrationRequest']/*[name()='subject1']/*[name()='assignedEntity']");
		Element assignedPrincipalOrganizationNode=departmentNode.element("assignedPrincipalOrganization");
		Element assignedEntityNode=(Element)document.selectSingleNode("/*[name()='PRPM_IN401030UV01']/*[name()='controlActProcess']/*[name()='subject']/*[name()='registrationRequest']/*[name()='author']/*[name()='assignedEntity']");
			department.setCreationTime(StringUtil.dateToString(new Date(),"yyyy-MM-dd"));
			department.setDbtIdentification(departmentNode.element("id").attributeValue("extension"));
			department.setDepartmentTypeCode(departmentNode.element("code").attributeValue("code"));
			department.setDepartmentTypeValue(departmentNode.element("code").attributeValue("displayName"));
			department.setDepartmentTypeCodeSystem(departmentNode.element("code").attributeValue("codeSystem"));
			department.setDepartmentTypeSystemName(departmentNode.element("code").attributeValue("codeSystemName"));
			department.setDbtName(assignedPrincipalOrganizationNode.element("name").getText());
			department.setHealthcareId(assignedEntityNode.element("id").attributeValue("extension"));
			department.setAssignedPreson(assignedEntityNode.element("representedOrganization").element("name").getText());
			department.setDbtIdentifications(assignedEntityNode.element("representedOrganization").element("id").attributeValue("extension"));
			department.setDepartmentName(assignedEntityNode.element("representedOrganization").element("name").getText());
			department.setContactPartyName(assignedEntityNode.element("representedOrganization").element("contactParty").element("contactPerson").element("name").getText());
			System.out.println(department.toString());
	} catch (DocumentException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
		return department;
		

	}
	
	/**
	 * 创建科室 AddOrganizationRequest (异常)
	 * */
	public DepartmentException departmentFailed(String message){
		DepartmentException departmentException = new DepartmentException();
    	departmentException.setCreationTime(StringUtil.dateToString(new Date(),"yyyy-MM-dd"));
    	departmentException.setRequestId(StringUtil.uuid());
    	departmentException.setTreatmentresult(""); 
		return departmentException;	
	}
	
	/**
	 * 文档注册服务--响应消息（成功） ProvideAndRegisterDocumentSet
	 * */
	public Fileregister fileRegSuccess(String message){
		Fileregister fileregister = new Fileregister();
		try {
			Document document = DocumentHelper.parseText(message);
			Element ProvideAndRegisterDocumentSetRequestNode=(Element)document.selectSingleNode("/*[name()='ProvideAndRegisterDocumentSetRequest']");
			fileregister.setRequestId(ProvideAndRegisterDocumentSetRequestNode.element("ID").attributeValue("extension"));
			fileregister.setResponseId(StringUtil.uuid());
			fileregister.setRepositoryId("");
            fileregister.setDoumentUrl("");
            fileregister.setStatus("AA");
		} catch (DocumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return fileregister;
	}
	
	/**
	 * 文档注册服务--响应消息（异常） ProvideAndRegisterDocumentSet
	 * */
	public FileregisterExction fileRegFailed(String message){
		FileregisterExction fileregisterExction = new FileregisterExction();
		
		try {
			Document document = DocumentHelper.parseText(message);
			Element ProvideAndRegisterDocumentSetRequestNode=(Element)document.selectSingleNode("/*[name()='ProvideAndRegisterDocumentSetRequest']");
			fileregisterExction.setRequestId(ProvideAndRegisterDocumentSetRequestNode.element("ID").attributeValue("extension"));
			fileregisterExction.setResponseId(StringUtil.uuid());
			fileregisterExction.setStatus("AE");
            fileregisterExction.setText("无法解析请求文档数据！");
		} catch (DocumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return fileregisterExction;
	
	}
	
	/**
	 * 文档检索服务--响应消息(成功) GetDocumentSetRetrieveInfo
	 * */
	public QueryFile queryFileSuccess(String message){
		QueryFile qf = new QueryFile();
		try {
			Document document = DocumentHelper.parseText(message);
			Element GetDocumentStroedInfoRequestNode=(Element)document.selectSingleNode("/*[name()='GetDocumentStroedInfoRequest']");
			
			String IdentityId=GetDocumentStroedInfoRequestNode.element("IdentityId").getText();
			String HealthCardId=GetDocumentStroedInfoRequestNode.element("HealthCardId").getText();
			String requestId=GetDocumentStroedInfoRequestNode.element("Id").attributeValue("extension");
			qf.setResponseId(StringUtil.uuid());
			qf.setRequestId(requestId);
			qf.setDocumentTitle("会诊记录");
			qf.setCreateTime(StringUtil.dateToString(new Date(),"yyyy-MM-dd"));
			qf.setAuthorName("刘善");
			qf.setPatientID("7760966");
			qf.setPatientName("胡惠");
			qf.setServerOrganization("YYY.YY");
			qf.setEpisodeID(">1111");
			qf.setInTime(StringUtil.dateToString(new Date(),"yyyy-MM-dd"));
			qf.setOutTime(StringUtil.dateToString(new Date(),"yyyy-MM-dd"));
			qf.setAdmissionDepart("皮肤科");
			qf.setAdmissionDoctor("李医生");
			qf.setAdmissionType("门诊");
			qf.setDiagnosisResult("皮肤过敏");
			qf.setDetail("状态描述详细信息");		
			
		} catch (DocumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return qf;
	}
	
	/**
	 * 文档检索服务--响应消息（失败）GetDocumentSetRetrieveInfo
	 * */
	public QueryFileExcrption queryFileFailed(String message){
		QueryFileExcrption qfe = new QueryFileExcrption();
		try {
			Document document = DocumentHelper.parseText(message);
			Element GetDocumentStroedInfoRequestNode=(Element)document.selectSingleNode("/*[name()='GetDocumentStroedInfoRequest']");	
			String IdentityId=GetDocumentStroedInfoRequestNode.element("IdentityId").getText();
			String HealthCardId=GetDocumentStroedInfoRequestNode.element("HealthCardId").getText();
			String requestId=GetDocumentStroedInfoRequestNode.element("Id").attributeValue("extension");
			qfe.setResponseId(StringUtil.uuid());
			qfe.setRequestId(requestId);
			qfe.setDetail("状态信息细节");
			
		} catch (DocumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return qfe;
	}
	
}
